<?php
 @session_start();
/*
 *  A Part of snock project
 *   Author king-of-war
 * Last modified 2009-4-21
 *
 */
$root_path = '../';
include_once $root_path . 'admin/smarty_config.php';
include_once $root_path . 'admin/class/fun_common.php';
include_once $root_path . 'admin/class/vote.class.php';
$vote = new vote($root_path);
$fun = new fun_common($root_path);
$max = $fun->getAll('vote', 1);
/*
 *
 * check identify
 */
include_once $root_path.'admin/class/verify.class.php';
$a=new verify($root_path);
$a->identity_check(3);



/*
 * page moudle start
 *
 */
 include_once $root_path . 'admin/class/cfg.class.php';
$cfg=new cfg($root_path);
  $page_size=$cfg->xml_read('page_num');
if (!empty ($_GET['p'])) {
	$page = $_GET['p'];
} else {
	$page = 1;
}
$pages = $fun->page($page, $page_size, $max);
/*
 * page moulde  end
 *  sort_read($arr)
 */
$arr[0] = $pages['start'];
$arr[1] = $page_size;
/*
 * read the sort_id & contant
 */
$a = $vote->vote_read($arr, 1);

$votes = array ();
for ($i = 0; $i < count($a); $i++) {
	$votes[$i]['id'] = $a[$i]->get_id();
	$votes[$i]['topic'] = $a[$i]->get_topic();
}
/*
 * get vote_se date
 */
$b = $vote->vote_read($arr, 3);

$vote_se = array ();
for ($i = 0; $i <count($b); $i++) {
	$vote_se[$i]['id'] = $b[$i]->get_id();
	$vote_se[$i]['se_id'] = $b[$i]->get_se_id();
	$vote_se[$i]['vote_id'] = $b[$i]->get_vote_id();
	$vote_se[$i]['contant'] = $b[$i]->get_contant();
}
/*
 * replace the vote_id with topic
 */
 for($i=0;$i<count($vote_se);$i++){
$vote_id=$vote_se[$i]['vote_id'];
for($a=0;$a<count($votes);$a++){
	if($vote_id==$votes[$a]['id'])
	$vote_id=$votes[$a]['topic'];
}
$vote_se[$i]['vote_id']=$vote_id;


 }
/*
 *vote delete moudle
 */

if (isset ($_POST['Submit'])) {
		$t = 0;
	$table=$_GET['table'];
	if($table=='votes'){


	for ($i = 0; $i <count($votes); $i++) {
		$id = $votes[$i]['id'];
		if ($_POST[$id] != '') {
			$ids[$t] = $id;
			$t++;
		}

	}
  $line= $vote->vote_del($ids,1);
	}else{
	for ($i = 0; $i < count($vote_se); $i++) {
		$id = $vote_se[$i]['id'];
				if ($_POST[$id] != '') {
			$ids[$t] = $id;
			$t++;
		}

	}
	print_r($ids);
	$line= $vote->vote_del($ids,2);
	}

	if ($line) {
		echo '<div align="center"><h1>成功删除' . $line . '条</h1></div>';
	} else {
		echo '<div align="center"><h1>删除失败</h1></div>';
	};
}
$smarty->assign("votes", $votes);
$smarty->assign("page", $pages);
$smarty->assign("vote_se", $vote_se);
$smarty->assign("url", $root_path);
$smarty->display("vote_del1.html");
?>
